// pages/my/mydeposit/mydeposit.js
Page({
  data: {
    cash: "",
    dialog_cash: false,
    paypwd: ""
  },
  onLoad: function (options) {
    this.getCash();
  },
  getCash() {
    getApp().globalData.http.myCash().then(res => {
      this.setData({
        cash: res.data.cash
      });
    });
  },
  submit() {
    if (this.data.cash == 0) {
      getApp().globalData.vant.toast("您还没有押金哦~");
      return;
    }
    if (!wx.getStorageSync("hasPayPwd")) {
      getApp().globalData.vant.dialog.confirm({
          title: "设置支付密码",
          message: "首次提现，请设置提现密码，请保存好密码，切勿泄露! ",
          closeOnClickOverlay: true,
          showCancelButton: false,
          confirmButtonText: "去设置",
          confirmButtonColor: "#33B868"
        })
        .then(() => {
          wx.navigateTo({
            url: "/pages/my/walletpasswordset/walletpasswordset",
          })
        })
        .catch(() => {});
    } else {
      this.setData({
        dialog_cash: true
      });
    }
  },
  pwdInput(e) {
    this.setData({
      paypwd: e.detail.value
    });
    if (e.detail.value.length == 6) {
      this.setData({
        dialog_cash: false,
        paypwd: ""
      });
      getApp().globalData.vant.toast.loading({
        message: "提现中...",
        duration: 0
      });
      getApp().globalData.http.getCash({
        type: 1,
        password: e.detail.value
      }).then(res => {
        getApp().globalData.vant.toast(res.msg);
      }).catch(e => {
        if (e.code == 400) {
          getApp().globalData.vant.toast.clear();
          getApp().globalData.vant.dialog.confirm({
              title: "温馨提示",
              message: "提现密码错误，请重试",
              cancelButtonText: "重试",
              confirmButtonText: "忘记密码",
              confirmButtonColor: "#33B868"
            })
            .then(() => {
              wx.navigateTo({
                url: "/pages/my/walletpasswordreset/walletpasswordreset",
              })
            })
            .catch(() => {
              this.setData({
                dialog_cash: true
              });
            });
        } else {
          getApp().globalData.vant.toast.clear();
          getApp().globalData.vant.toast(e.msg);
        }
      });
    }
  }
})